<?php
include 'AuthenticatedUserController.php';
class User_IndexController extends User_AuthenticatedUserController {
	public function preDispatch() {
		//レイアウトを設定する
    	$layoutPath = APPLICATION_PATH  . '/templates/user/user';
		$option = array (	'layout' 		=> 'index', 
              	        'layoutPath' 	=> $layoutPath );
		Zend_Layout::startMvc ( $option );
		
		//アクティブメニューを設定
        $this->view->active_menu = "home";
	}
	
	function indexAction() {
		//TODO　必要なクラスを読み込む
		Zend_Loader::loadClass("SelectListModel");
		Zend_Loader::loadClass("RoomModel");
		Zend_Loader::loadClass("OrderModel");	
		Zend_Loader::loadClass("AuthModel");
		
		$request = $this->getRequest();
		$view = $this->view;
		
		//パラメーターを取得
		$date = $request->getParam("date");
		if(!$date)
			$date = date("Y-m-d");

		$authModel = new AuthModel();
		$user_id = $authModel->getUserInfo("id");
		$user_id = $user_id ? $user_id : 1;
		
		//TODO 会議室モデルとオーだモデルのインスタンスを作成
		$room_model = new RoomModel();
		$order_model = new OrderModel();
		
		//TODO 会議室と予約の一覧を読み出す
		$room_list = $room_model->getListRoom("all", "", NULL);
		$list_room_have_order = array();
		foreach ($room_list as &$room){
			$room['order_list'] = $order_model->getListOrderOnRoom($room['id'], $date, $user_id);
			if(count($room['order_list']))
				$list_room_have_order[] = $room;
		}
		
		//TODO 必要データをビューに送る
		$view->room_list = $list_room_have_order;
		$view->date = $date; 

		//TODO Navigator を設定
    	$nav['ホーム'] = "/user";
    	$nav['マイページ'] = "/user";
    	$view->nav = $nav;
	}	
	
	public function registAction(){
		
	}
}